package com.ktgj.other.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.other.domain.EtDimCity;
import com.ktgj.other.service.IEtDimCityService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 城市Controller
 * 
 * @author ruoyi
 * @date 2022-07-22
 */
@RestController
@RequestMapping("/city")
public class EtDimCityController extends BaseController
{
    @Autowired
    private IEtDimCityService etDimCityService;

    /**
     * 查询城市列表
     */
    @PreAuthorize(hasPermi = "other:city:list")
    @GetMapping("/list")
    public TableDataInfo list(EtDimCity etDimCity)
    {
        startPage();
        List<EtDimCity> list = etDimCityService.selectEtDimCityList(etDimCity);
        return getDataTable(list);
    }

    /**
     * 导出城市列表
     */
    @PreAuthorize(hasPermi = "other:city:export")
    @Log(title = "城市", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EtDimCity etDimCity) throws IOException
    {
        List<EtDimCity> list = etDimCityService.selectEtDimCityList(etDimCity);
        ExcelUtil<EtDimCity> util = new ExcelUtil<EtDimCity>(EtDimCity.class);
        util.exportExcel(response, list, "城市数据");
    }

    /**
     * 获取城市详细信息
     */
    @PreAuthorize(hasPermi = "other:city:query")
    @GetMapping(value = "/{cityid}")
    public AjaxResult getInfo(@PathVariable("cityid") Long cityid)
    {
        return AjaxResult.success(etDimCityService.selectEtDimCityById(cityid));
    }

    /**
     * 新增城市
     */
    @PreAuthorize(hasPermi = "other:city:add")
    @Log(title = "城市", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EtDimCity etDimCity)
    {
        return toAjax(etDimCityService.insertEtDimCity(etDimCity));
    }

    /**
     * 修改城市
     */
    @PreAuthorize(hasPermi = "other:city:edit")
    @Log(title = "城市", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EtDimCity etDimCity)
    {
        return toAjax(etDimCityService.updateEtDimCity(etDimCity));
    }

    /**
     * 删除城市
     */
    @PreAuthorize(hasPermi = "other:city:remove")
    @Log(title = "城市", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cityids}")
    public AjaxResult remove(@PathVariable Long[] cityids)
    {
        return toAjax(etDimCityService.deleteEtDimCityByIds(cityids));
    }
}
